import {ActionTree, Module} from 'vuex'
import {AssetBundleState, RootState} from '../types'
import {url} from '@/store/utils'
import {AxiosPromise} from 'axios'
const namespaced: boolean = true

const actions: ActionTree<AssetBundleState, RootState> = {
  list(context, payload) {
    return axios.post(url(`/api/asset-bundle/list`), payload)
  },
  add(context, payload) {
    return axios.post(url(`/api/asset-bundle/add`), payload)
  },
  update(context, payload) {
    return axios.post(url(`/api/asset-bundle/update/${payload.id}`), payload)
  },
  fetchBundleItems(context, payload) {
    let {id, data} = payload
    return axios.post(url(`/api/asset-bundle/items/list/${id}`), data)
  },
  queryAssets(context, query): AxiosPromise {
    return axios.post(url(`/api/asset-bundle/asset/query`), {query})
  },
  addAsset(context, payload): AxiosPromise{
    let {id, data} = payload
    return axios.post(url(`/api/asset-bundle/items/add/${id}`), data)
  },
  delItemByIds(context, payload): AxiosPromise{
    return axios.post(url(`/api/asset-bundle/items/del-by-ids`), payload)
  }
}

export const AssetBundle: Module<AssetBundleState, RootState> = {
  namespaced,
  actions
}

export default AssetBundle